package com.xunyin.modules.file.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xunyin.enums.ErrorEnum;
import com.xunyin.modules.file.service.FileService;
import com.xunyin.utils.CommonUtil;
import com.xunyin.utils.alioss.AliOssCustomConst;
import com.xunyin.utils.alioss.AliyunOSSClientUtil;
import com.xunyin.utils.alioss.UUIDHexGenerator;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Service
public class FileServiceImpl implements FileService {


    @Override
    public JSONObject uploadSingle(MultipartFile file, String folderName) {

        if (file != null) {
            String filepaths;
            String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
            filepaths = UUIDHexGenerator.getUUIDHex() + suffixName;
            Map<String, String> result = AliyunOSSClientUtil.uploadFile(file, AliOssCustomConst.OSS_COMPLAINT_FILE_URL + folderName + "/", filepaths);
            return CommonUtil.successJson(result);
        }
        return CommonUtil.errorJson(ErrorEnum.E_100016);
    }

    @Override
    public JSONObject uploadMultiple(MultipartFile[] file, String folderName) {

        return CommonUtil.successJson();
    }
}
